<?php
// Include the class
include 'create.kml.php';

// Create a new KML object
$kml = new KML;

$styles = array(
  array('myStyle','iconId','http://example.com/icon.gif'),
  array('myStyle2','iconId2','http://example.com/icon2.gif')
);

foreach($styles as $style) {
  $s = new KMLStyle;
  $s->id = $style[0]; // Id of the style for use in placemarks
  $s->iconid = $style[1]; // Icon ID
  $s->iconhref = $style[2]; // Link to the icon

  // Add the style to the KML
  $kml->addItem($s);
}

// Get the data from the database
$q = mysql_query('SELECT id,name,desc,link,city,state,country,coords FROM table;');

while(list($id,$name,$desc,$folder,$coords,$style) = mysql_fetch_row($q)) {
  // Create a new place object
  $p = new KMLPlace;

  // Assign bits of the array
  $p->id = $id;
  $p->name = $name;
  $p->desc = $desc;
  $p->folder = $folder;
  $p->style = $style;
  $p->coords = $coords;

  // If you have HTML in both name and desc call this
  //$p->setCDATA();

  // If you have HTML in just desc then call this
  //$p->setCDATA('desc');

  // Add the item to the kml
  $kml->addItem($p);
}

// Create the KML
$kml->printHeader('xml'); // Allows the KML to be viewed in the browser
//$kml->printHeader(); // Forces the user to download the KML file

// Print the KML to the browser
echo $kml->create();

// Save the file as well if we want
$kml->save('output.kml');
?>